#include "Date.h"


Date::Date(int year , int month , int day ) {
	_year = year;
	_month = month;
	_day = day;

}


bool Date::operator<(const Date& b) {
	if (_year != b._year) {
		return _year < b._year;
	}
	else if (_month != b._month) {
		return _month < b._month;
	}
	else {
		return _day < b._day;
	}
}
bool Date::operator==(const Date& b) {
	if (_year != b._year || _month != b._month || _day != b._day) {
		return false;
	}
	return true;
}

bool Date::operator>(const Date& b) {
	if (*this < b || *this == b)
		return false;
	else
		return true;
}

bool Date::operator!=(const Date& b) {
	return !(*this == b);
}

int Date::getmonthday(int year, int month) {
	static int day[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
	if (month != 2)
		return day[month];
	else if ((year % 4 == 0 && year % 100 != 4) || year % 400 == 0) {
		return 29;
	}
	else
		return 28;
}


Date& Date::operator+=(int day) {
	_day += day;
	while (_day > getmonthday(_year,_month)) {
		_day -= getmonthday(_year,_month);
		_month++;
		if (_month > 12) {
			_month = 1;
			_year++;
		}
	}
	return *this;
}

Date Date::operator+(int day) {
	Date tmp(*this);
	tmp._day += day;
	while (tmp._day > getmonthday(tmp._year, tmp._month)) {
		tmp._day -= getmonthday(tmp._year, tmp._month);
		tmp._month++;
		if (tmp._month > 12) {
			tmp._month = 1;
			tmp._year++;
		}
	}
	return tmp;
}